package ca.qc.bdeb.info.pp2.tp2.application;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

public class QuartierDAO
{
    public static List<Quartier> listerQuartier(String[] idsVilles)
    {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        String requete = "from Quartier where 1=1";

        if (idsVilles != null)
            requete += " and id_ville=:ville" + 0;

        for (int i = 1; i < idsVilles.length; i++)
            requete += " or id_ville=:ville" + i;

        Query query = session.createQuery(requete);

        for (int i = 0; i < idsVilles.length; i++)
            query.setString("ville" + i, idsVilles[i]);
        return (List<Quartier>) (query.list());
    }

    public static List<Quartier> getQuartiersChoisis(String[] idsQuartiers)
    {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        String requete = "from Quartier where 1=1";

        if (idsQuartiers != null)
            requete += " and id_quartier=:quartier" + 0;

        for (int i = 1; i < idsQuartiers.length; i++)
            requete += " or id_quartier=:quartier" + i;

        Query query = session.createQuery(requete);

        for (int i = 0; i < idsQuartiers.length; i++)
            query.setString("quartier" + i, idsQuartiers[i]);

        return (List<Quartier>) (query.list());
    }
}
